<?php
if( ! defined('BASEPATH')) exit('No direct script access allowed');

class wallpage extends CI_Controller
{


	function __construct()
	{
		parent::__construct();
		// check if user logged in
		if(!$this->ion_auth->logged_in()){
			redirect('auth/login');
		}
		$this->load->library('form_validation');
		$this->load->model('founder/wallpage_model');
	}
	function viewwall($id=null)
	{
		//$data['userid'] = $id;
		if(isset($id))
		{
			$user= $id;
		}else
		{
			$user=$this->session->userdata('user_id');		
		}
		$data['userid'] = $user;
		$data['designationbyid'] = $this->wallpage_model->designationbyid($user);
		$data['userdetails'] = $this->wallpage_model->userdetails($user);
		$data['coffeebyid'] = $this->wallpage_model->coffeebyid($user);
		$data['badges'] = $this->wallpage_model->badges_getall();
		//$data['toolschart'] = $this->about_model->toolschart($user);
		$data['user'] = $this->wallpage_model->get_user_details($this->session->userdata('user_id'));
		
		$meta['page_title'] = "Wall";
		$this->load->view('common/header',$meta);
		$this->load->view('founder/view-wallpage',$data);
		$this->load->view('common/footer');
		//echo $id;

	}
	
	function assign_badges()
	{
				
			$users = $this->input->post('users');
			$badgesid = $this->input->post('badges');
			
			$combine_badges = array();
			
			for($x=0;$x<count($badgesid);$x++)
			{
				$combine_badges[$x]['user_id'] = $users;
				$combine_badges[$x]['badges_id'] = $badgesid[$x];
			}
	
								
		$this->wallpage_model->user_badges_insert($combine_badges);
	}
	function star()
	{	
	$userfrom = $this->session->userdata('user_id');	
			if(isset($userfrom))
			{
				$star=1;
			}
			$userto = $this->input->post('users');
			
			$date = date('Y/m/d H:i:s');
			$insert = array('user_id'=>$userto,
						'star'=>$star,
						'date'=>$date);
			$this->wallpage_model->star_insert($insert);
			redirect('founder/wallpage/viewwall','refresh');
	}

}	
